1
2
3
4 package org.apache.velocity.tools.generic;
5
6 import org.ieee.shinobu.demo.velocity.AbstractVelocityTestCase;
7
8 /***
9 * @author shinobu
10 */
11 public class ArrayToolTest extends AbstractVelocityTestCase {
12
13 public void testListObject() throws Exception {
14 this.getContext().put("arrays", new ArrayTool());
15 this.getContext().put("primes", new String[] {"two", "three", "five"});
16
17 this.setTemplate("" +
18 "#set($list = $arrays.list($primes))\n" +
19 "$list.get(1)\n" +
20 "");
21
22 this.setExpected("" +
23 "three\n" +
24 "");
25
26 this.assertVelocity();
27 }
28
29 public void testListLong() throws Exception {
30 this.getContext().put("arrays", new ArrayTool());
31 this.getContext().put("primes", new long[] {2l, 3l, 5l});
32
33 this.setTemplate("" +
34 "#set($list = $arrays.list($primes))\n" +
35 "$list.get(1)\n" +
36 "");
37
38 this.setExpected("" +
39 "3\n" +
40 "");
41
42 this.assertVelocity();
43 }
44
45 public void testListInt() throws Exception {
46 this.getContext().put("arrays", new ArrayTool());
47 this.getContext().put("primes", new int[] {2, 3, 5});
48
49 this.setTemplate("" +
50 "#set($list = $arrays.list($primes))\n" +
51 "$list.get(1)\n" +
52 "");
53
54 this.setExpected("" +
55 "3\n" +
56 "");
57
58 this.assertVelocity();
59 }
60
61 public void testListShort() throws Exception {
62 this.getContext().put("arrays", new ArrayTool());
63 this.getContext().put("primes", new short[] {2, 3, 5});
64
65 this.setTemplate("" +
66 "#set($list = $arrays.list($primes))\n" +
67 "$list.get(1)\n" +
68 "");
69
70 this.setExpected("" +
71 "3\n" +
72 "");
73
74 this.assertVelocity();
75 }
76
77 public void testListByte() throws Exception {
78 this.getContext().put("arrays", new ArrayTool());
79 this.getContext().put("primes", new byte[] {2, 3, 5});
80
81 this.setTemplate("" +
82 "#set($list = $arrays.list($primes))\n" +
83 "$list.get(1)\n" +
84 "");
85
86 this.setExpected("" +
87 "3\n" +
88 "");
89
90 this.assertVelocity();
91 }
92
93 public void testListChar() throws Exception {
94 this.getContext().put("arrays", new ArrayTool());
95 this.getContext().put("primes", new char[] {'2', '3', '5'});
96
97 this.setTemplate("" +
98 "#set($list = $arrays.list($primes))\n" +
99 "$list.get(1)\n" +
100 "");
101
102 this.setExpected("" +
103 "3\n" +
104 "");
105
106 this.assertVelocity();
107 }
108
109 public void testListDouble() throws Exception {
110 this.getContext().put("arrays", new ArrayTool());
111 this.getContext().put("primes", new double[] {2.0, 3.0, 5.0});
112
113 this.setTemplate("" +
114 "#set($list = $arrays.list($primes))\n" +
115 "$list.get(1)\n" +
116 "");
117
118 this.setExpected("" +
119 "3.0\n" +
120 "");
121
122 this.assertVelocity();
123 }
124
125 public void testListFloat() throws Exception {
126 this.getContext().put("arrays", new ArrayTool());
127 this.getContext().put("primes", new float[] {2.0f, 3.0f, 5.0f});
128
129 this.setTemplate("" +
130 "#set($list = $arrays.list($primes))\n" +
131 "$list.get(1)\n" +
132 "");
133
134 this.setExpected("" +
135 "3.0\n" +
136 "");
137
138 this.assertVelocity();
139 }
140
141 public void testListBoolean() throws Exception {
142 this.getContext().put("arrays", new ArrayTool());
143 this.getContext().put("bools", new boolean[] {false, true, false});
144
145 this.setTemplate("" +
146 "#set($list = $arrays.list($bools))\n" +
147 "$list.get(1)\n" +
148 "");
149
150 this.setExpected("" +
151 "true\n" +
152 "");
153
154 this.assertVelocity();
155 }
156
157 public void testListNotAnArray() throws Exception {
158 this.getContext().put("arrays", new ArrayTool());
159 this.getContext().put("primes", "2^7-1");
160
161 this.setTemplate("" +
162 "$arrays.list($primes)\n" +
163 "");
164
165 this.setExpected("" +
166 "$arrays.list($primes)\n" +
167 "");
168
169 this.assertVelocity();
170 }
171
172 public void testListNullArray() throws Exception {
173 this.getContext().put("arrays", new ArrayTool());
174
175 this.setTemplate("" +
176 "$arrays.list($primes)\n" +
177 "");
178
179 this.setExpected("" +
180 "$arrays.list($primes)\n" +
181 "");
182
183 this.assertVelocity();
184 }
185
186 public void testGetObject() throws Exception {
187 this.getContext().put("arrays", new ArrayTool());
188 this.getContext().put("primes", new String[] {"two", "three", "five"});
189
190 this.setTemplate("" +
191 "$arrays.get($primes, 1)\n" +
192 "");
193
194 this.setExpected("" +
195 "three\n" +
196 "");
197
198 this.assertVelocity();
199 }
200
201 public void testGetLong() throws Exception {
202 this.getContext().put("arrays", new ArrayTool());
203 this.getContext().put("primes", new long[] {2, 3, 5});
204
205 this.setTemplate("" +
206 "$arrays.get($primes, 1)\n" +
207 "");
208
209 this.setExpected("" +
210 "3\n" +
211 "");
212
213 this.assertVelocity();
214 }
215
216 public void testGetInt() throws Exception {
217 this.getContext().put("arrays", new ArrayTool());
218 this.getContext().put("primes", new int[] {2, 3, 5});
219
220 this.setTemplate("" +
221 "$arrays.get($primes, 1)\n" +
222 "");
223
224 this.setExpected("" +
225 "3\n" +
226 "");
227
228 this.assertVelocity();
229 }
230
231 public void testGetShort() throws Exception {
232 this.getContext().put("arrays", new ArrayTool());
233 this.getContext().put("primes", new short[] {2, 3, 5});
234
235 this.setTemplate("" +
236 "$arrays.get($primes, 1)\n" +
237 "");
238
239 this.setExpected("" +
240 "3\n" +
241 "");
242
243 this.assertVelocity();
244 }
245
246 public void testGetByte() throws Exception {
247 this.getContext().put("arrays", new ArrayTool());
248 this.getContext().put("primes", new byte[] {2, 3, 5});
249
250 this.setTemplate("" +
251 "$arrays.get($primes, 1)\n" +
252 "");
253
254 this.setExpected("" +
255 "3\n" +
256 "");
257
258 this.assertVelocity();
259 }
260
261 public void testGetChar() throws Exception {
262 this.getContext().put("arrays", new ArrayTool());
263 this.getContext().put("primes", new char[] {'2', '3', '5'});
264
265 this.setTemplate("" +
266 "$arrays.get($primes, 1)\n" +
267 "");
268
269 this.setExpected("" +
270 "3\n" +
271 "");
272
273 this.assertVelocity();
274 }
275
276 public void testGetDouble() throws Exception {
277 this.getContext().put("arrays", new ArrayTool());
278 this.getContext().put("primes", new double[] {2.0, 3.0, 5.0});
279
280 this.setTemplate("" +
281 "$arrays.get($primes, 1)\n" +
282 "");
283
284 this.setExpected("" +
285 "3.0\n" +
286 "");
287
288 this.assertVelocity();
289 }
290
291 public void testGetFloat() throws Exception {
292 this.getContext().put("arrays", new ArrayTool());
293 this.getContext().put("primes", new float[] {2.0f, 3.0f, 5.0f});
294
295 this.setTemplate("" +
296 "$arrays.get($primes, 1)\n" +
297 "");
298
299 this.setExpected("" +
300 "3.0\n" +
301 "");
302
303 this.assertVelocity();
304 }
305
306 public void testGetBoolean() throws Exception {
307 this.getContext().put("arrays", new ArrayTool());
308 this.getContext().put("bools", new boolean[] {false, true, false});
309
310 this.setTemplate("" +
311 "$arrays.get($bools, 1)\n" +
312 "");
313
314 this.setExpected("" +
315 "true\n" +
316 "");
317
318 this.assertVelocity();
319 }
320
321 public void testGetOutOfBounds() throws Exception {
322 this.getContext().put("arrays", new ArrayTool());
323 this.getContext().put("primes", new int[] {2, 3, 5});
324
325 this.setTemplate("" +
326 "$arrays.get($primes, 5)\n" +
327 "");
328
329 this.setExpected("" +
330 "$arrays.get($primes, 5)\n" +
331 "");
332
333 this.assertVelocity();
334 }
335
336 public void testGetNotAnArray() throws Exception {
337 this.getContext().put("arrays", new ArrayTool());
338 this.getContext().put("primes", "2^7-1");
339
340 this.setTemplate("" +
341 "$arrays.get($primes, 5)\n" +
342 "");
343
344 this.setExpected("" +
345 "$arrays.get($primes, 5)\n" +
346 "");
347
348 this.assertVelocity();
349 }
350
351 public void testGetNullArray() throws Exception {
352 this.getContext().put("arrays", new ArrayTool());
353
354 this.setTemplate("" +
355 "$arrays.get($primes, 5)\n" +
356 "");
357
358 this.setExpected("" +
359 "$arrays.get($primes, 5)\n" +
360 "");
361
362 this.assertVelocity();
363 }
364
365 public void testLengthObject() throws Exception {
366 this.getContext().put("arrays", new ArrayTool());
367 this.getContext().put("primes", new String[] {"two", "three", "five"});
368
369 this.setTemplate("" +
370 "$arrays.length($primes)\n" +
371 "");
372
373 this.setExpected("" +
374 "3\n" +
375 "");
376
377 this.assertVelocity();
378 }
379
380 public void testLengthLong() throws Exception {
381 this.getContext().put("arrays", new ArrayTool());
382 this.getContext().put("primes", new long[] {2l, 3l, 5l});
383
384 this.setTemplate("" +
385 "$arrays.length($primes)\n" +
386 "");
387
388 this.setExpected("" +
389 "3\n" +
390 "");
391
392 this.assertVelocity();
393 }
394
395 public void testLengthInt() throws Exception {
396 this.getContext().put("arrays", new ArrayTool());
397 this.getContext().put("primes", new int[] {2, 3, 5});
398
399 this.setTemplate("" +
400 "$arrays.length($primes)\n" +
401 "");
402
403 this.setExpected("" +
404 "3\n" +
405 "");
406
407 this.assertVelocity();
408 }
409
410 public void testLengthShort() throws Exception {
411 this.getContext().put("arrays", new ArrayTool());
412 this.getContext().put("primes", new short[] {2, 3, 5});
413
414 this.setTemplate("" +
415 "$arrays.length($primes)\n" +
416 "");
417
418 this.setExpected("" +
419 "3\n" +
420 "");
421
422 this.assertVelocity();
423 }
424
425 public void testLengthByte() throws Exception {
426 this.getContext().put("arrays", new ArrayTool());
427 this.getContext().put("primes", new byte[] {2, 3, 5});
428
429 this.setTemplate("" +
430 "$arrays.length($primes)\n" +
431 "");
432
433 this.setExpected("" +
434 "3\n" +
435 "");
436
437 this.assertVelocity();
438 }
439
440 public void testLengthChar() throws Exception {
441 this.getContext().put("arrays", new ArrayTool());
442 this.getContext().put("primes", new char[] {'2', '3', '5'});
443
444 this.setTemplate("" +
445 "$arrays.length($primes)\n" +
446 "");
447
448 this.setExpected("" +
449 "3\n" +
450 "");
451
452 this.assertVelocity();
453 }
454
455 public void testLengthDouble() throws Exception {
456 this.getContext().put("arrays", new ArrayTool());
457 this.getContext().put("primes", new double[] {2.0, 3.0, 5.0});
458
459 this.setTemplate("" +
460 "$arrays.length($primes)\n" +
461 "");
462
463 this.setExpected("" +
464 "3\n" +
465 "");
466
467 this.assertVelocity();
468 }
469
470 public void testLengthFloat() throws Exception {
471 this.getContext().put("arrays", new ArrayTool());
472 this.getContext().put("primes", new float[] {2.0f, 3.0f, 5.0f});
473
474 this.setTemplate("" +
475 "$arrays.length($primes)\n" +
476 "");
477
478 this.setExpected("" +
479 "3\n" +
480 "");
481
482 this.assertVelocity();
483 }
484
485 public void testLengthBoolean() throws Exception {
486 this.getContext().put("arrays", new ArrayTool());
487 this.getContext().put("bools", new boolean[] {false, true, false});
488
489 this.setTemplate("" +
490 "$arrays.length($bools)\n" +
491 "");
492
493 this.setExpected("" +
494 "3\n" +
495 "");
496
497 this.assertVelocity();
498 }
499
500 public void testLengthNotAnArray() throws Exception {
501 this.getContext().put("arrays", new ArrayTool());
502 this.getContext().put("primes", "2^7-1");
503
504 this.setTemplate("" +
505 "$arrays.length($primes)\n" +
506 "");
507
508 this.setExpected("" +
509 "$arrays.length($primes)\n" +
510 "");
511
512 this.assertVelocity();
513 }
514
515 public void testLengthNullArray() throws Exception {
516 this.getContext().put("arrays", new ArrayTool());
517
518 this.setTemplate("" +
519 "$arrays.length($primes)\n" +
520 "");
521
522 this.setExpected("" +
523 "$arrays.length($primes)\n" +
524 "");
525
526 this.assertVelocity();
527 }
528
529 public void testSetObject() throws Exception {
530 this.getContext().put("arrays", new ArrayTool());
531 this.getContext().put("primes", new String[] {"two", "three", "five"});
532
533 this.setTemplate("" +
534 "$arrays.set($primes, 1, 'one')\n" +
535 "$arrays.get($primes, 1)\n" +
536 "");
537
538 this.setExpected("" +
539 "\n" +
540 "one\n" +
541 "");
542
543 this.assertVelocity();
544 }
545
546 public void testSetLong() throws Exception {
547 this.getContext().put("arrays", new ArrayTool());
548 this.getContext().put("primes", new long[] {2, 3, 5});
549 this.getContext().put("one", new Long(1));
550
551 this.setTemplate("" +
552 "$arrays.set($primes, 1, $one)\n" +
553 "$arrays.get($primes, 1)\n" +
554 "");
555
556 this.setExpected("" +
557 "\n" +
558 "1\n" +
559 "");
560
561 this.assertVelocity();
562 }
563
564 public void testSetInt() throws Exception {
565 this.getContext().put("arrays", new ArrayTool());
566 this.getContext().put("primes", new int[] {2, 3, 5});
567 this.getContext().put("one", new Integer(1));
568
569 this.setTemplate("" +
570 "$arrays.set($primes, 1, $one)\n" +
571 "$arrays.get($primes, 1)\n" +
572 "");
573
574 this.setExpected("" +
575 "\n" +
576 "1\n" +
577 "");
578
579 this.assertVelocity();
580 }
581
582 public void testSetShort() throws Exception {
583 this.getContext().put("arrays", new ArrayTool());
584 this.getContext().put("primes", new short[] {2, 3, 5});
585 this.getContext().put("one", new Short((short) 1));
586
587 this.setTemplate("" +
588 "$arrays.set($primes, 1, $one)\n" +
589 "$arrays.get($primes, 1)\n" +
590 "");
591
592 this.setExpected("" +
593 "\n" +
594 "1\n" +
595 "");
596
597 this.assertVelocity();
598 }
599
600 public void testSetByte() throws Exception {
601 this.getContext().put("arrays", new ArrayTool());
602 this.getContext().put("primes", new byte[] {2, 3, 5});
603 this.getContext().put("one", new Byte((byte) 1));
604
605 this.setTemplate("" +
606 "$arrays.set($primes, 1, $one)\n" +
607 "$arrays.get($primes, 1)\n" +
608 "");
609
610 this.setExpected("" +
611 "\n" +
612 "1\n" +
613 "");
614
615 this.assertVelocity();
616 }
617
618 public void testSetChar() throws Exception {
619 this.getContext().put("arrays", new ArrayTool());
620 this.getContext().put("primes", new char[] {'2', '3', '5'});
621 this.getContext().put("one", new Character('1'));
622
623 this.setTemplate("" +
624 "$arrays.set($primes, 1, $one)\n" +
625 "$arrays.get($primes, 1)\n" +
626 "");
627
628 this.setExpected("" +
629 "\n" +
630 "1\n" +
631 "");
632
633 this.assertVelocity();
634 }
635
636 public void testSetDouble() throws Exception {
637 this.getContext().put("arrays", new ArrayTool());
638 this.getContext().put("primes", new double[] {2.0, 3.0, 5.0});
639 this.getContext().put("one", new Double(1.0));
640
641 this.setTemplate("" +
642 "$arrays.set($primes, 1, $one)\n" +
643 "$arrays.get($primes, 1)\n" +
644 "");
645
646 this.setExpected("" +
647 "\n" +
648 "1.0\n" +
649 "");
650
651 this.assertVelocity();
652 }
653
654 public void testSetFloat() throws Exception {
655 this.getContext().put("arrays", new ArrayTool());
656 this.getContext().put("primes", new float[] {2.0f, 3.0f, 5.0f});
657 this.getContext().put("one", new Float(1.0));
658
659 this.setTemplate("" +
660 "$arrays.set($primes, 1, $one)\n" +
661 "$arrays.get($primes, 1)\n" +
662 "");
663
664 this.setExpected("" +
665 "\n" +
666 "1.0\n" +
667 "");
668
669 this.assertVelocity();
670 }
671
672 public void testSetBoolean() throws Exception {
673 this.getContext().put("arrays", new ArrayTool());
674 this.getContext().put("bools", new boolean[] {false, true, false});
675
676 this.setTemplate("" +
677 "$arrays.set($bools, 1, false)\n" +
678 "$arrays.get($bools, 1)\n" +
679 "");
680
681 this.setExpected("" +
682 "\n" +
683 "false\n" +
684 "");
685
686 this.assertVelocity();
687 }
688
689 public void testSetOutOfBounds() throws Exception {
690 this.getContext().put("arrays", new ArrayTool());
691 this.getContext().put("primes", new int[] {2, 3, 5});
692
693 this.setTemplate("" +
694 "$arrays.set($primes, 5, 1)\n" +
695 "");
696
697 this.setExpected("" +
698 "$arrays.set($primes, 5, 1)\n" +
699 "");
700
701 this.assertVelocity();
702 }
703
704 public void testSetNotAnArray() throws Exception {
705 this.getContext().put("arrays", new ArrayTool());
706 this.getContext().put("primes", "2^7-1");
707
708 this.setTemplate("" +
709 "$arrays.set($primes, 5, 'one')\n" +
710 "");
711
712 this.setExpected("" +
713 "$arrays.set($primes, 5, 'one')\n" +
714 "");
715
716 this.assertVelocity();
717 }
718
719 public void testSetNullArray() throws Exception {
720 this.getContext().put("arrays", new ArrayTool());
721
722 this.setTemplate("" +
723 "$arrays.set($primes, 5, 'one')\n" +
724 "");
725
726 this.setExpected("" +
727 "$arrays.set($primes, 5, 'one')\n" +
728 "");
729
730 this.assertVelocity();
731 }
732
733 public void testCloneObject() throws Exception {
734 this.getContext().put("arrays", new ArrayTool());
735 this.getContext().put("primes", new String[] {"two", "three", "five"});
736
737 this.setTemplate("" +
738 "#set($clone = $arrays.clone($primes))\n" +
739 "$arrays.set($primes, 1, 'one')\n" +
740 "$arrays.get($primes, 1)\n" +
741 "$arrays.get($clone, 1)\n" +
742 "");
743
744 this.setExpected("" +
745 "\n" +
746 "one\n" +
747 "three\n" +
748 "");
749
750 this.assertVelocity();
751 }
752
753 public void testCloneLong() throws Exception {
754 this.getContext().put("arrays", new ArrayTool());
755 this.getContext().put("primes", new long[] {2, 3, 5});
756 this.getContext().put("one", new Long(1));
757
758 this.setTemplate("" +
759 "#set($clone = $arrays.clone($primes))\n" +
760 "$arrays.set($primes, 1, $one)\n" +
761 "$arrays.get($primes, 1)\n" +
762 "$arrays.get($clone, 1)\n" +
763 "");
764
765 this.setExpected("" +
766 "\n" +
767 "1\n" +
768 "3\n" +
769 "");
770
771 this.assertVelocity();
772 }
773
774 public void testCloneInt() throws Exception {
775 this.getContext().put("arrays", new ArrayTool());
776 this.getContext().put("primes", new int[] {2, 3, 5});
777 this.getContext().put("one", new Integer(1));
778
779 this.setTemplate("" +
780 "#set($clone = $arrays.clone($primes))\n" +
781 "$arrays.set($primes, 1, $one)\n" +
782 "$arrays.get($primes, 1)\n" +
783 "$arrays.get($clone, 1)\n" +
784 "");
785
786 this.setExpected("" +
787 "\n" +
788 "1\n" +
789 "3\n" +
790 "");
791
792 this.assertVelocity();
793 }
794
795 public void testCloneShort() throws Exception {
796 this.getContext().put("arrays", new ArrayTool());
797 this.getContext().put("primes", new short[] {2, 3, 5});
798 this.getContext().put("one", new Short((short) 1));
799
800 this.setTemplate("" +
801 "#set($clone = $arrays.clone($primes))\n" +
802 "$arrays.set($primes, 1, $one)\n" +
803 "$arrays.get($primes, 1)\n" +
804 "$arrays.get($clone, 1)\n" +
805 "");
806
807 this.setExpected("" +
808 "\n" +
809 "1\n" +
810 "3\n" +
811 "");
812
813 this.assertVelocity();
814 }
815
816 public void testCloneByte() throws Exception {
817 this.getContext().put("arrays", new ArrayTool());
818 this.getContext().put("primes", new byte[] {2, 3, 5});
819 this.getContext().put("one", new Byte((byte) 1));
820
821 this.setTemplate("" +
822 "#set($clone = $arrays.clone($primes))\n" +
823 "$arrays.set($primes, 1, $one)\n" +
824 "$arrays.get($primes, 1)\n" +
825 "$arrays.get($clone, 1)\n" +
826 "");
827
828 this.setExpected("" +
829 "\n" +
830 "1\n" +
831 "3\n" +
832 "");
833
834 this.assertVelocity();
835 }
836
837 public void testCloneChar() throws Exception {
838 this.getContext().put("arrays", new ArrayTool());
839 this.getContext().put("primes", new char[] {'2', '3', '5'});
840 this.getContext().put("one", new Character('1'));
841
842 this.setTemplate("" +
843 "#set($clone = $arrays.clone($primes))\n" +
844 "$arrays.set($primes, 1, $one)\n" +
845 "$arrays.get($primes, 1)\n" +
846 "$arrays.get($clone, 1)\n" +
847 "");
848
849 this.setExpected("" +
850 "\n" +
851 "1\n" +
852 "3\n" +
853 "");
854
855 this.assertVelocity();
856 }
857
858 public void testCloneDouble() throws Exception {
859 this.getContext().put("arrays", new ArrayTool());
860 this.getContext().put("primes", new double[] {2.0, 3.0, 5.0});
861 this.getContext().put("one", new Double(1.0));
862
863 this.setTemplate("" +
864 "#set($clone = $arrays.clone($primes))\n" +
865 "$arrays.set($primes, 1, $one)\n" +
866 "$arrays.get($primes, 1)\n" +
867 "$arrays.get($clone, 1)\n" +
868 "");
869
870 this.setExpected("" +
871 "\n" +
872 "1.0\n" +
873 "3.0\n" +
874 "");
875
876 this.assertVelocity();
877 }
878
879 public void testCloneFloat() throws Exception {
880 this.getContext().put("arrays", new ArrayTool());
881 this.getContext().put("primes", new float[] {2.0f, 3.0f, 5.0f});
882 this.getContext().put("one", new Float(1.0));
883
884 this.setTemplate("" +
885 "#set($clone = $arrays.clone($primes))\n" +
886 "$arrays.set($primes, 1, $one)\n" +
887 "$arrays.get($primes, 1)\n" +
888 "$arrays.get($clone, 1)\n" +
889 "");
890
891 this.setExpected("" +
892 "\n" +
893 "1.0\n" +
894 "3.0\n" +
895 "");
896
897 this.assertVelocity();
898 }
899
900 public void testCloneBoolean() throws Exception {
901 this.getContext().put("arrays", new ArrayTool());
902 this.getContext().put("bools", new boolean[] {false, true, false});
903 this.getContext().put("false", Boolean.FALSE);
904
905 this.setTemplate("" +
906 "#set($clone = $arrays.clone($bools))\n" +
907 "$arrays.set($bools, 1, $false)\n" +
908 "$arrays.get($bools, 1)\n" +
909 "$arrays.get($clone, 1)\n" +
910 "");
911
912 this.setExpected("" +
913 "\n" +
914 "false\n" +
915 "true\n" +
916 "");
917
918 this.assertVelocity();
919 }
920
921 public void testCloneNotAnArray() throws Exception {
922 this.getContext().put("arrays", new ArrayTool());
923 this.getContext().put("primes", "2^7-1");
924
925 this.setTemplate("" +
926 "#set($clone = $arrays.clone($primes))\n" +
927 "$clone\n" +
928 "");
929
930 this.setExpected("" +
931 "$clone\n" +
932 "");
933
934 this.assertVelocity();
935 }
936
937 public void testCloneNullArray() throws Exception {
938 this.getContext().put("arrays", new ArrayTool());
939
940 this.setTemplate("" +
941 "#set($clone = $arrays.clone($primes))\n" +
942 "$clone\n" +
943 "");
944
945 this.setExpected("" +
946 "$clone\n" +
947 "");
948
949 this.assertVelocity();
950 }
951
952 public void testIsArray() {
953 assertTrue(new ArrayTool().isArray(new Object[0]));
954 assertTrue(new ArrayTool().isArray(new long[0]));
955 assertTrue(new ArrayTool().isArray(new int[0]));
956 assertTrue(new ArrayTool().isArray(new short[0]));
957 assertTrue(new ArrayTool().isArray(new byte[0]));
958 assertTrue(new ArrayTool().isArray(new char[0]));
959 assertTrue(new ArrayTool().isArray(new double[0]));
960 assertTrue(new ArrayTool().isArray(new float[0]));
961 assertTrue(new ArrayTool().isArray(new boolean[0]));
962 }
963
964 public void testNotArray() {
965 assertFalse(new ArrayTool().isArray(""));
966 assertFalse(new ArrayTool().isArray(null));
967 }
968
969 }